#include <bits/stdc++.h>
#define int long long

using namespace std;

int n, a[200001], b[200001];

signed main(){
	freopen("color.in", "r", stdin);
	freopen("color.out", "w", stdout);
	int T; scanf("%lld", &T);
	while(T--){
		scanf("%lld", &n);
		for(int i = 0; i < n; i++){
			scanf("%lld", a + i);
		}
		int maxv = 0;
		for(int i = 0; i < (1LL << n); i++){
			for(int j = 0; j < n; j++)
				if((i >> j) & 1LL)
					b[j] = 1;
				else b[j] = 0;
			int ls[2] = {-1, -1}, ans = 0;
			for(int j = 0; j < n; j++){
				if(ls[b[j]] == a[j]) ans += a[j];
				ls[b[j]] = a[j];
			}
			maxv = max(maxv, ans);
		}
		printf("%lld\n", maxv);
	}
	return 0;
}
